package gamePieces;



import gameComponents.Board;
import gameComponents.Player;

import java.awt.Point;
import java.util.ArrayList;

/**
 * Class for the chess piece of a Bishop
 *
 */
public class Bishop extends Piece{
	/**
	 * Default constructor for Bishop object.
	 * X and Y coordinates of Bishop are set in the superclass Piece. 
	 * 
	 * @param x coordinate of Bishop
	 * @param y coordinate of Bishop
	 */
	public Bishop(int x, int y, Player player) {
		super(x,y, player);
	}
	/**
	 * @return The string representation of a Bishop on the board.
	 * @author Vivian Andreeva
	 * @modified by Selman Selman
	 */
	public String toString() {
		if (getOwnership().getId()==1) {
		return "B";
		}
		return "b";
		}
	@Override
	/**
	  * Overrides abstract method in superclass Piece.
	  * Calculates list of all possible moves of
	  * the Bishop object at its current position.
	  * Bishop piece can move diagonally any number of times.
	  * @author Vivian Andreeva
	  * @return an ArrayList of all the possible points the Bishop could IDEALLY reach.
	  */
	public ArrayList<Point> possibleMoves() {
		int x = super.getX();
		int y = super.getY();
		moves = new ArrayList<Point>();
		
		//all possible moves in the down positive diagonal
		for(int j = y + 1, i = x+1 ; j < Board.SIZE && i < Board.SIZE ; j++, i++){
			moves.add(new Point(i,j));
		}
		//all possible moves in the up positive diagonal
		for(int j = y - 1, i = x+1 ; j >= 0 && i < Board.SIZE ; j--, i++){
			moves.add(new Point(i,j));
		}
		//all possible moves in the up negative diagonal
		for(int j = y - 1, i = x-1 ; j >= 0 && i >= 0 ; j--, i--){
			moves.add(new Point(i,j));
		}
		//all possible moves in the down negative diagonal
		for(int j = y + 1, i = x-1 ; j < Board.SIZE && i >= 0 ; j++, i--){
			moves.add(new Point(i,j));
	}
		return moves;
}
	/**
	 * checks if move of Bishop is legal
	 * @author Selman Selman and Jordan Beland
	 * @param x coordinate of new location
	 * @param y coordinate of new location
	 * @return true if the move to the new location would be legal
	 */
	public boolean checkIfLegal(int x, int y){
		if(x < 0 || x > Board.SIZE){
			return false;
		} else if(y < 0 || y > Board.SIZE){
			return false;
		} else{
			int xDiff = Math.abs(super.getX() - x);
			int yDiff = Math.abs(super.getY() - y);
			if (xDiff == yDiff){
				return true;
			} 
		}
		return false;
	}
}
